package com.hashTable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class IntersectionofTwoArrays0130_349 {
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> res = new HashSet<>();
        HashSet<Integer> hs = new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            hs.add(nums1[i]);
        }

        for (int i : nums2) {
            if(hs.contains(i)) res.add(i);
        }
        return res.stream().mapToInt(x -> x).toArray();
    }
}
